/**
 * Represents a vertex-weight pair.
 * 
 * @param <V>
 *            The Vertex inteface's implementing type
 */
public class Pair<V extends Vertex<V>> {
	private V vertex;
	private int weight;

	/**
	 * Initializes a new vertex-weight pair.
	 * 
	 * @param vertex
	 *            The vertex
	 * @param weight
	 *            The weight
	 */
	public Pair(V vertex, int weight) {
		this.vertex = vertex;
		this.weight = weight;
	}

	/**
	 * Initializes a new vertex-weight pair with the default weight (0).
	 * 
	 * @param vertex
	 *            The vertex
	 */
	public Pair(V vertex) {
		this(vertex, 0);
	}

	/**
	 * Returns the vertex.
	 * 
	 * @return The vertex
	 */
	public V getVertex() {
		return vertex;
	}

	/**
	 * Returns the weight.
	 * 
	 * @return The weight
	 */
	public int getWeight() {
		return weight;
	}

	/**
	 * Determines if two Pairs are equal. Two Pairs are considered equal if both
	 * their vertices and weights are equal.
	 * 
	 * @param o
	 *            The Pair to compare this against
	 * @return true if this Pair is equal to the given argument, or false
	 *         otherwise
	 */
	@Override
	@SuppressWarnings("unchecked")
	public boolean equals(Object o) {
		boolean equal = false;

		if (o instanceof Pair) {
			Pair<V> other = (Pair<V>) o;
			equal = vertex.equals(other.vertex) && weight == other.weight;
		}

		return equal;
	}

	/**
	 * Returns this Pair as a String in the form "(vertex, weight)".
	 * 
	 * @return The String representation of this Pair
	 */
	@Override
	public String toString() {
		return "(" + vertex + ", " + weight + ")";
	}
}
